package com.clusterswisdom.horn.api.tmall.meger;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import com.alibaba.fastjson.JSONObject;
import com.clusterswisdom.horn.api.db.DefaultStructMeger;
import com.clusterswisdom.horn.api.db.StructMeger;
import com.clusterswisdom.horn.api.ioc.struct.StructConfig;
import com.clusterswisdom.horn.api.ioc.struct.StructContainer;

public class TradeMeger extends DefaultStructMeger implements StructMeger {

	@Override
	public Object megerStruct(Connection conn, StructConfig struct, JSONObject data) throws SQLException {
		Object tradeId = super.megerStruct(conn, struct, data);
		StructConfig orderStruct = StructContainer.getContainer().getStruct("Order");
		
		List<JSONObject> datas = (List<JSONObject>)data.get("orderItem");
		if (datas != null) {
			for (JSONObject jsonObject : datas) {
				super.megerStruct(conn, orderStruct, jsonObject);
			}
		}
		
		return tradeId;
	}
}
